package cn.cjxy.userms.controller;

import cn.cjxy.userms.entity.User;
import cn.cjxy.userms.service.UserService;
import cn.cjxy.userms.service.impl.UserServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;

/**
 * 修改的数据回显
 */
@WebServlet("/findUserById")
public class UserDetailServlet extends HttpServlet {
    UserService userService=new UserServiceImpl();
    @Override
    protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        //取出路径参数中的id
        int id = Integer.parseInt(req.getParameter("id"));
        //根据id查出用户信息
        User userById = userService.findUserById(id);
        //传入update.jsp 完成数据回显
        req.setAttribute("user", userById);
        req.getRequestDispatcher("/update.jsp").forward(req, resp);

    }
}
